var express = require('express')
// 1. 创建一个路由容器
var router = express.Router()

//###############     首页 ################################
//首页
router.get('/home/multidata', function(req, res) {
    const data = require('./data/home_multidata');
    res.json(data);
    // res.json({success_code: 200, message: data});
})

router.get('/home/data', function(req, res) {
    var url = require("url");
    //params就是get方法携带的参数
    var params = url.parse(req.url, true).query;
    let type = params.type;
    let dataFile = '';
    if(type == 'new'){
        dataFile = './data/home_data_new';
    }else if(type == 'pop'){
        dataFile = './data/home_data_pop';
    }else if(type == 'sell'){
        dataFile = './data/home_data_sell';
    }
    const data = require(dataFile);
    res.json(data);
})

//###############     分类 ################################
router.get('/category', function(req, res) {
    const data = require('./data/category');
    res.json(data);
})

router.get('/subcategory', function(req, res) {
    const data = require('./data/subcategory');
    res.json(data);
})

router.get('/subcategory/detail', function(req, res) {
    var url = require("url");
    //params就是get方法携带的参数
    var params = url.parse(req.url, true).query;
    let type = params.type;
    let dataFile = '';
    if(type == 'new'){
        dataFile = './data/subcategory_detail_new';
    }else if(type == 'pop'){
        dataFile = './data/subcategory_detail_pop';
    }else if(type == 'sell'){
        dataFile = './data/subcategory_detail_sell';
    }
    const data = require(dataFile);
    res.json(data);
})
//###############     商品详情 ################################
router.get('/recommend', function(req, res) {
    const data = require('./data/recommend');
    res.json(data);
})

router.get('/detail', function(req, res) {
    const data = require('./data/detail');
    res.json(data);
})
//demo
router.get('/get', function(req, res) {
    res.send('请求了/get')
})

router.post('/add', function(req, res) {
res.send('请求了 /add')
})


  //最后导出
module.exports = router
